<?php

namespace App\Http\Middleware;

use App\Http\Model\ShopAccount;
use Closure;

class SetAccountId
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if($request->has('openid')){
            $account = ShopAccount::where('openid',$request->openid)->first();
            if($account != null){
                $request->session()->put('account_id',$account->id);
            }
        }
        return $next($request);
    }
}
